package chenji.watcher;

import java.io.File;
import java.util.logging.Logger;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

import chenji.watcher.core.ConfigException;
import chenji.watcher.core.ConfigManager;
import chenji.watcher.core.WatchGroupEditorManager;
import chenji.watcher.core.WatchGroupManager;
import chenji.watcher.listeners.CommandWatcher;
import chenji.watcher.listeners.WatcherListener;

public final class Main extends JavaPlugin {
	private static File datafolder;
	private static Logger log;
	private static ConfigManager cm;
	private static WatchGroupManager wgm;
	private static WatchGroupEditorManager wgcm;
	private BukkitTask task;

	public void onEnable() {
		getLogger().info("-----------------Watcher-----------------");
		getLogger().info("作者：ChenJi，来自Unknown Domain 公益计划");
		
		Main.log = getLogger();
		Main.datafolder = getDataFolder();
		Main.wgm = new WatchGroupManager();

		Main.wgcm = new WatchGroupEditorManager();
		getCommand("watcher").setExecutor(new CommandWatcher());
		try {
			cm = new ConfigManager();
		} catch (ConfigException e) {
			e.printStackTrace();
		}
		task = new BukkitRunnable() {
			@Override
			public void run() {
				Main.getWatchGroupManager().Task();

			}

		}.runTaskTimer(this, 20L, 10);
		getServer().getPluginManager().registerEvents(new WatcherListener(), this);
		getLogger().info("----------------------------------------");
	}

	public void onDisable() {
		task.cancel();
	}

	public static Logger getLog() {
		return Main.log;
	}

	public static File getKDataFolder() {
		return Main.datafolder;
	}

	public static WatchGroupManager getWatchGroupManager() {
		return Main.wgm;
	}

	public static ConfigManager getConfigManager() {

		return Main.cm;
	}

	public static WatchGroupEditorManager getWatchGroupEditorManager() {
		return Main.wgcm;
	}
}
